package com.xyx.ssm.action;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.xyx.ssm.jdbcdao.syorgDao;
import com.xyx.ssm.po.SyOrg;
import com.xyx.ssm.po.Syauthority;
import com.xyx.ssm.service.SyorgService;

@Controller
@RequestMapping(value = "/syorgjiekou")
public class SyorgAction {
	@Resource(name = "syorgService")
	@Autowired
	private SyorgService syorgService;

	/**
	 * 查询所有数据
	 * @return
	 */
	@RequestMapping("/syorgselect")
	@ResponseBody
	public List<Map<String, Object>> syauthorityadd() {
		System.out.println(syorgService.selectSyorgadd());
		return syorgService.selectSyorgadd();
	}

	/**
	 * 提供页面入口（权限管理页面）
	 */
	@RequestMapping("/syorgshouye")
	public String syorgshouye() {
		System.out.println("---------------------------------------------------------------------");
		return "syorgpage/syorg";
	}
	
	
	/**
	 * 增加权限
	 * 
	 * @throws IOException
	 */
	@RequestMapping("/syorginsert")
	@ResponseBody
	public Map<String, Object> syorgInsert(SyOrg syOrg) {
		
			int num = syorgService.syorgadd(syOrg);
			Map<String, Object> mapjson = new HashMap<String, Object>();
			if (num > 0) {
				mapjson.put("flag", true);
				mapjson.put("msg", "添加成功！");
			} else {
				mapjson.put("flag", false);
				mapjson.put("msg", "添加失败！");
			}
			return mapjson;
	

	}

	
	/**
	 * 修改
	 */
	@RequestMapping("/syorgupdate")
	@ResponseBody
	public Map<String, Object> Syorgupdate(SyOrg syOrg){
		//SyOrg syOrg =new SyOrg();
		int num=syorgService.syorgupdate(syOrg);
		Map<String, Object> mapjson = new HashMap<String, Object>();
		if(num>0){
			mapjson.put("flag", true);
			mapjson.put("msg", "修改成功！");
		}else{
			mapjson.put("flag", false);
			mapjson.put("msg", "修改失败！");
		}
		return mapjson ;
	}


	/**
	 * 删除
	 */

	@RequestMapping("/syorgydelete")
	@ResponseBody
	public Map<String, Object> Syorgdelete(String id) {
		if(id!=null&id!=""){
		int num = syorgService.syorgdelete(id);
		Map<String, Object> mapjson = new HashMap<String, Object>();
		if (num > 0) {
			mapjson.put("flag", true);
			mapjson.put("msg", "删除成功！");
		} else {
			mapjson.put("flag", false);
			mapjson.put("msg", "删除失败！");

		}
		return mapjson;
		}else{
			Map<String, Object> mapjson = new HashMap<String, Object>();
			mapjson.put("flag", false);
			mapjson.put("msg", "至少选择一个！");
			return mapjson;
		}
	}
}

